package Text29;

import java.util.*;

public class Main {
    static int N = 100010,INF = 0x3f3f3f3f;
    public static Range[] ranges=new Range[N];
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n=scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int a=scanner.nextInt();
            int b=scanner.nextInt();
            ranges[i]=new Range(a,b);
        }
        Arrays.sort(ranges,0,n);
        int res=0;
        int ed=-INF;
        for (int i = 0; i < n; i++) {
            if(ranges[i].l>ed){
                res++;
                ed=ranges[i].r;
            }
        }
        System.out.println(res);
    }
}

class Range implements Comparable<Range>{
    public int l,r;

    public Range(int l, int r) {
        this.l = l;
        this.r = r;
    }

    @Override
    public int compareTo(Range o) {
        return Integer.compare(r,o.r);
    }
}